package com.fmsz.xmly.fragments;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.fmsz.xmly.R;
import com.fmsz.xmly.adapters.SubscriptionAdapter;
import com.fmsz.xmly.callbacks.SubscroptionPage;
import com.fmsz.xmly.fragments.subscriptionfgts.HistoryFragment;
import com.fmsz.xmly.fragments.subscriptionfgts.RecommendFragment;
import com.fmsz.xmly.fragments.subscriptionfgts.SubscripFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class SubscriptionFragment extends Fragment implements SubscroptionPage {

    private TabLayout tabLayout_subscription;
    private ViewPager viewPager_subscription;
    private List<String> titles;
    private List<Fragment> fragments;
    private SubscriptionAdapter adapter;
    private RecommendFragment recommendFragment;
    private HistoryFragment historyFragment;
    private SubscripFragment subscripFragment;

    public SubscriptionFragment() {
        // Required empty public constructor

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_subscription, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        tabLayout_subscription = (TabLayout) view.findViewById(R.id.tabLayout_Subscription);
        viewPager_subscription = (ViewPager) view.findViewById(R.id.viewPage_Subscription);
        titles = new ArrayList<>();
        titles.add("推荐");
        titles.add("订阅");
        titles.add("历史");
        fragments = new ArrayList<>();
        recommendFragment = new RecommendFragment();
        historyFragment = new HistoryFragment();
        subscripFragment = new SubscripFragment(this);
        fragments.add(recommendFragment);
        fragments.add(subscripFragment);
        fragments.add(historyFragment);

        adapter = new SubscriptionAdapter(getFragmentManager(), titles, fragments);
        viewPager_subscription.setAdapter(adapter);
        tabLayout_subscription.setupWithViewPager(viewPager_subscription);
        viewPager_subscription.setCurrentItem(1);
    }

    @Override
    public void setCurrentPage() {
        viewPager_subscription.setCurrentItem(0);
    }
}
